﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommunitySystemModel;
using System.Collections.ObjectModel;
using CommunitySystem.BO;
using System.Data;

namespace CommunitySystem
{
  public static class Emp_BDGLBO
    {
      public static ObservableCollection<Emp_BDGLModel> GetSYQMKH(string con, int index, int pagesize)
        {
            ObservableCollection<Emp_BDGLModel> rights = new ObservableCollection<Emp_BDGLModel>();
            string sql = "";
            sql = string.Format(@"select top({0}) ROW_NUMBER() over(order by ID desc) as Sequence,IsSelected='false'
                                ,* from
                                (
                                select ROW_NUMBER() over(order by ID desc) as rowsID,* from Emp_BDGL emp where 1=1 {2}
                                ) a where a.rowsID>=
                                (
                                SELECT ISNULL(MAX(rowsID),0) FROM 
                                (
                                select top({0}*({1}-1)+1) * from
                                (
                                select ROW_NUMBER() over(order by ID desc) as rowsID,* from Emp_BDGL emp where 1=1 {2}
                                )b
                                )c
                                ) order by OrgID", pagesize, index, con);


            DataSet ds = AccessHelper.GetInstance().ExcuteDataSet(sql);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                Emp_BDGLModel khm = new Emp_BDGLModel();
                khm = Emp_BDGLModel.FillEntity(dr);
              
                rights.Add(khm);
            }
            return rights;
        }
        public static int GetSYQMKHCount(string con)
        {
            string sql = string.Format(@"select  COUNT(id) from Emp_BDGL emp where 1=1 {0} ", con);
            if (!string.IsNullOrEmpty(con))
            {
                sql += con;
            }

            DataSet ds = AccessHelper.GetInstance().ExcuteDataSet(sql);
            return Convert.ToInt32(ds.Tables[0].Rows[0][0]);
        }

        public static bool SYQMKH_SB(Emp_BDGLModel model)
        {
            string sql = string.Format(@"UPDATE Emp_BDGL
   SET [XRZW] = '{0}',[NRZW] ='{1}' ,[NMZW] = '{2}',[RMLY] ='{3}',[BZ] = '{4}'
 WHERE ID ={5}", model.XRZW,model.NRZW,model.NMZW,model.RMLY,model.BZ,model.Id);
            if (AccessHelper.GetInstance().ExecuteNonQuery(sql) > 0) return true;
            else return false;
        }
    }
}
